package com.bluefox.hospital.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bluefox.common.web.exception.CustomRuntimeException;
import com.bluefox.hospital.service.VideoService;
import com.bluefox.hospital.model.Video;
import com.bluefox.hospital.repository.VideoRepository;
import lombok.NonNull;

/**
 * VideoService 实现类
 */
@Service
@Transactional
public class VideoServiceImpl implements VideoService {

    @Autowired
    private VideoRepository videoRepository;

    @Override
    @Transactional(readOnly = true)
    public Video get(@NonNull Long id) {
        final  Video model = videoRepository.findById(id).get();
        if (model == null) {
            throw new CustomRuntimeException("404", String.format("查找的资源[%s]不存在.", id));
        }
        return model;
    }

    @Override
    public Video create(Video model) {
        // TODO: 业务逻辑
        return videoRepository.save(model);
    }

    @Override
    public Video update(Video model) {
        // TODO: 业务逻辑
        return videoRepository.save(model);
    }

    @Override
    public void delete(@NonNull Long id) {
        // TODO: 业务逻辑
        videoRepository.deleteById(id);
    }
}
